<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%@ include file="/common/message.jsp"%>
<%@ include file="/common/user.jsp"%>
<%
    String id = input.getDesc("id", "-1");
    Integer uid = token.getUid();
    List<Arrangement> list = QBuilder.db("basedb").select().from("Arrangement").where(new Where("hospital=", hospital).and("status=", STATUS_ENABLE).and("uid=", uid).and("id=", id)).query().getResultObj();
    if (isEmpty(list)) {
        msg = new Message(30041, "日程已不存在");
        Tools.encryptPrint(out, msg);
        return;
    }
    Arrangement ag = list.get(0);
    String team = ag.getTeam();
    List<Arrangement> ags = QBuilder.db("basedb").select().from("Arrangement").where(new Where("hospital=", hospital).and("status=", STATUS_ENABLE).and("team=", team)).query().getResultObj();
    if (isEmpty(ags)) {
        msg = new Message(30041, "暂无日程");
        msg.put("data", new ArrayList());
        Tools.encryptPrint(out, msg);
        return;
    }
    List<Integer> uids = new ArrayList<Integer>();
    for (int i = 0; i < ags.size(); i++) {
        ag = ags.get(i);
        ag.setStatus(STATUS_DISABLE);
        uids.add(ag.getUid());
        uids.add(ag.getPartner());
    }
    Map<Integer, User> users = usersByUids(uids);
    DBTools.db("basedb").modItem(ags);
    for (int i = 0; i < ags.size(); i++) {
        ag = ags.get(i);
        Information info = new Information();
        info.setOid(ag.getId()+"");
        info.setHospital(ag.getHospital());
        info.setTitle("日程通知");
        info.setSumary("日程");
        info.setCategory(4);
        User user =  users.get(ag.getUid());
        String author = user.getName();
        user =  users.get(ag.getPartner());
        String joiner = user.getName();
        info.setContent(joiner + "您好, "+author+"删除了日程。\n内容:"+ag.getTitle()+"\n日期:"+ag.getStart());
        createMsg(info, ag.getPartner());
    }
    Tools.encryptPrint(out, msg);
%>
